#! python2
# -*- coding: utf-8 -*-
import string
import commands
PLATFORM_NAME = 'Android'
import subprocess

def run_cmd(cmd,  shell=True):
    """执行cmd命令，返回结果

    :param cmd:
    :param shell:
    :return: stdout
    """

    stdout, stderr = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()  # wait 如果输出量多，会死锁
    if stderr:
        print(stderr)
    result = [i.decode('utf-8') for i in stdout.splitlines()]
    return result

print run_cmd("adb shell getprop ro.build.version.release")

PLATFORM_VERSION = string.strip(commands.getoutput('adb shell getprop ro.build.version.release'))  # 获取手机系统版本  gbk
DEVICE_NAME = string.strip(commands.getoutput('adb shell getprop ro.serialno'))  # 获取手机序列号
# PHONE_NAME = string.strip(commands.getoutput('adb shell getprop ro.build.id'))
# print(PHONE_NAME.encdoe("utf-8"))


#煎饼的建议  不使用commands 使用subprocess
def run_cmd(cmd, print_result=False, shell=True):
    """执行cmd命令，返回结果

    :param cmd:
    :param print_result: 是否打印，默认False
    :param shell:
    :return: stdout
    """

    stdout, stderr = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()  # wait 如果输出量多，会死锁

    if print_result:
        print(stdout)

    if stderr:
        print(stderr)
    result = [i.decode('utf-8') for i in stdout.splitlines()]
    return result